#! /bin/bash
#rm -r /etc/pacman.d/gnupg/
#pacman-key --init
#pacman-key --populate msys2

#curl -O https://repo.msys2.org/msys/x86_64/msys2-keyring-1~20220623-1-any.pkg.tar.zst
#curl -O https://repo.msys2.org/msys/x86_64/msys2-keyring-1~20220623-1-any.pkg.tar.zst.sig
# shoud unzip to tar

cp etc / -r
cp usr / -r
cp util / -r

[[ ! -d /var/lib/pacman ]] && mkdir -p /var/lib/pacman

rm /etc/pacman.d/gnupg -rf
pacman-key --init
pacman-key --populate
# imprt gpg key
pacman -U --noconfirm --config <(echo) cyin/msys2-keyring-1~20220623-1-any.pkg.tar
pacman -Syu

# npm and yarn conf
cp cyin/.npmrc ~
cp cyin/.yarnrc ~
cp cyin/.gitconfig ~
cp cyin/.zshrc ~

userhome=`echo ~`
userhome=$(echo "${userhome}" | sed -e 's/\//\\&/g' )
sed -i "s/\[USER_HOME\]/${userhome}/g" ~/.zshrc > /dev/null

# setup oh-my-zsh
unzip -qo cyin/.oh-my-zsh.zip -d ~

#set zsh as default shell
if ! grep -i "\[\[ -t 1 \]\] && exec zsh" ~/.bashrc; then
  echo "[[ -t 1 ]] && exec zsh" > ~/.bashrc
fi
